(ns projectname.handler
  (:use [compojure.core]
        [projectname.routes.home :only [home-routes]])
  (:require [compojure.route :as route]
            [noir.util.middleware :as noir-middleware]
            [taoensso.timbre :as timbre]
            [com.postspectacular.rotor :as rotor]))

(defn init []
  (timbre/info "projectname is starting")
  ;https://github.com/ptaoussanis/timbre
  (timbre/set-config!
    [:appenders :rotor]
    {:min-level             :debug
     :enabled?              true
     :async?                false
     :max-message-per-msecs nil
     :fn                    rotor/append})
  (timbre/set-config!
    [:shared-appender-config :rotor]
    {:path     "logs/app.log"
     :max-size (* 512 1024)
     :backlog  10})
  (timbre/info "projectname started successfully"))

(defn destroy []
  (timbre/info "projectname is shutting down"))

(declare app-routes)
(defroutes app-routes
           (route/resources "/")
           (route/not-found "Not Found"))

(def app (-> [#'home-routes #'app-routes]
             (noir-middleware/app-handler)))